﻿using BrnMall.Manager.Domain.Ship;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BrnMall.Manager.Manager.Ship
{
    /// <summary>
    /// 配送资金账户
    /// </summary>
    public class ShipCashManager
    {
        /// <summary>
        /// 添加会员余额记录
        /// </summary>
        /// <param name="model"></param>
        public static void Add(ShipCash model)
        {
            using (var db = new QDMallDatabase())
            {
                db.Insert(model);
            }
        }

        /// <summary>
        /// 返回配送余额
        /// </summary>
        /// <param name="storeId"></param>
        /// <returns></returns>
        public static ShipCash GetInfo(int storeId)
        {
            using (var db = new QDMallDatabase())
            {
                return db.SingleOrDefault<ShipCash>(string.Format("select top 1 * from bma_shipCash where storeid={0}", storeId));
            }
        }


        /// <summary>
        /// 更新余额
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="cash">余额</param>
        /// <param name="giveCash">赠送总金额(从开通到现在为止的赠送总金额)</param>
        /// <returns></returns>
        public static int UpdateCash(int storeId, string cash)
        {
            try
            {
                using (var db = new QDMallDatabase())
                {
                    return db.Execute("update bma_shipCash set cash=@0 where storeId=@1", cash, storeId);
                }
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                throw;
            }
        }

        /// <summary>
        /// 更新达达门店状态
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="shopState">达达门店状态(0 未开通, 1已开通)</param>
        /// <returns></returns>
        public static int UpdateShopState(int storeId, int shopState)
        {
            using (var db = new QDMallDatabase())
            {
                return db.Execute("update bma_shipCash set shopState=@0 where storeId=@1", shopState, storeId);
            }
        }
    }
}
